package com.common.handler;

import cn.hutool.json.JSONUtil;
import com.common.exception.StefanieException;
import com.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author: stefanie-zy
 * @time: 2024/1/27-13:41
 * @description: 全局异常处理
 */
@RestControllerAdvice
@Slf4j
public class StefanieExceptionHandler {

    /**
     * 系统异常
     *
     * @return Result
     */
    @ExceptionHandler(StefanieException.class)
    public Result<?> handleSysException(StefanieException stefanieException) {
        log.error("{}：", stefanieException.getMessage());
        log.info("RESPONSE:{}", JSONUtil.toJsonStr(stefanieException));
        return Result.fail(stefanieException.getCode(), stefanieException.getMessage());
    }
}
